<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once("database.php");

class profile_handler extends database{
    public $result;

            function  __construct() {
                parent::__construct();
            }

            function  __destruct() {

            }

            function get_nama_lengkap($usr_id){
                $query = "SELECT nama_lengkap FROM user WHERE usr_email='$usr_id'";
                $this->exec_q($query, "nama_lengkap");
            }

            function get_wall_privacy($usr_id){
                $query = "SELECT wall_privacy FROM user WHERE usr_email='$usr_id'";
                $this->exec_q($query, "wall_privacy");
            }

            function set_nama_lengkap($usr_id, $val){
                $query = "UPDATE user SET nama_lengkap='$val' WHERE usr_email='$usr_id'";
                $this->connect();
                mysql_query($query, $this->conn);
                mysql_close();
            }

            function get_password($usr_id){
                $query = "SELECT password FROM user WHERE usr_email='$usr_id'";
                $this->exec_q($query, "password");
            }

            function set_password($usr_id, $val){
                $query = "UPDATE user SET password='$val' WHERE usr_email='$usr_id'";
                $this->connect();
                mysql_query($query, $this->conn);
                mysql_close();
            }

            function set_wall_privacy($usr_id, $val){
                $query = "UPDATE user SET wall_privacy='$val' WHERE usr_email='$usr_id'";
                $this->connect();
                mysql_query($query, $this->conn);
                mysql_close();
            }
            
            function edit_details($usr_id, $type, $val){ //type 1 = birth, type 2 = lokasi, type 3 = hobi, tyoe 4 = profile picture
               if ($type == 1){
                    $query = "UPDATE user SET birthday='$val' WHERE usr_email='$usr_id'";
                }
                else if ($type == 2){
                    $query = "UPDATE user SET lokasi='$val' WHERE usr_email='$usr_id'";
                }
                else if ($type == 3){
                    $query = "UPDATE user SET hobi='$val' WHERE usr_email='$usr_id'";
                }
                else if ($type == 4){
                    $query = "UPDATE user SET profic_id=$val WHERE usr_email='$usr_id'";
                }
                else{
                    $query="";
                }

		$this->connect();
		mysql_query($query,$this->conn);
		mysql_close();
            }

            function del_details($usr_id, $type){ //type 1 = birth, type 2 = lokasi, type 3 = hobi
                
                if ($type == 1){
                    $query = "UPDATE user SET birthday=NULL WHERE usr_email='$usr_id'";
                }
                else if ($type == 2){
                    $query = "UPDATE user SET lokasi=NULL WHERE usr_email='$usr_id'";
                }
                else if ($type == 3){
                    $query = "UPDATE user SET hobi=NULL WHERE usr_email='$usr_id'";
                }
                else if ($type == 4){
                    $query = "UPDATE user SET profpic_id=NULL WHERE usr_email='$usr_id'";
                }
                else{
                    $query="";
                }
                
				$this->connect();
				mysql_query($query,$this->conn);
				mysql_close();
            }

            function retr_details($usr_id, $type){
                $query = "SELECT * FROM user WHERE usr_email='$usr_id'";

                if ($type == 1){
                    $res = $this->exec_q($query, "birthday");
                }
                else if ($type == 2){
                    $res = $this->exec_q($query, "lokasi");
                }
                else if ($type == 3){
                    $res = $this->exec_q($query, "hobi");
                }
                else if ($type == 4){
                    $res = $this->exec_q($query, "profpic_id");
                }
                else if ($type == 5){ //retrieve all
                    $res[0] = $this->exec_q($query, "birthday");
                    $res[1] = $this->exec_q($query, "lokasi");
                    $res[2] = $this->exec_q($query, "hobi");
                    $res[3] = $this->exec_q($query, "profpic_id");
                    $res[4] = $this->exec_q($query, "nama_lengkap");
					$res[5] = $this->exec_q($query, "wall_privacy");
                }

                $this->result = $res;
            }

}

?>
